//
//  HWHomeTopThreeRankCell.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/25.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWHomeTopThreeRankCell: UICollectionViewCell {
    
    var bgView:UIView!
    var tagImageView:UIImageView!
    var logoImageView:UIImageView!
    var labelBgImageView:UIImageView!
    var nameLabel:UILabel!
    var lowUserLabel:UILabel!
    var lowUserNumLabel:UILabel!
    
    var indexPath:IndexPath? {
        didSet {
            if indexPath?.row == 0 {
                tagImageView.image = UIImage(named: "num_first")
                logoImageView.image = UIImage(named: "goldMedal")
                labelBgImageView.image = UIImage(named: "goldLabelBg")
                nameLabel.textColor = .colorWithHexString(hexString: "#FFBC2E")
            } else if indexPath?.row == 1 {
                tagImageView.image = UIImage(named: "num_second")
                logoImageView.image = UIImage(named: "silverMedal")
                labelBgImageView.image = UIImage(named: "silverLabelBg")
                nameLabel.textColor = .colorWithHexString(hexString: "#A3A3A3")
            } else if indexPath?.row == 2 {
                tagImageView.image = UIImage(named: "num_three")
                logoImageView.image = UIImage(named: "bronzeMedal")
                labelBgImageView.image = UIImage(named: "bronzeLabelBg")
                nameLabel.textColor = .colorWithHexString(hexString: "#D98A21")
            }
        }
    }
    
    var model:HWHomeRankListModel? {
        didSet {
            nameLabel.text = model?.name
            lowUserNumLabel.text = model?.num
        }
    }
    
    var popularityListModel:HWRankListModel? {
        didSet {
            lowUserLabel.text = "活跃人数"
            nameLabel.text = popularityListModel?.gname
            lowUserNumLabel.text = popularityListModel?.count
        }
    }
    
    var consumeRankModel:HWConsumeRankModel? {
        didSet {
            lowUserLabel.text = "充值"
            nameLabel.text = consumeRankModel?.gname
            lowUserNumLabel.text = consumeRankModel?.money
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWHomeTopThreeRankCell {
    private func initUI() -> Void {
        bgView = UIView()
        bgView.backgroundColor = .white
        bgView.layer.cornerRadius = 12*widthScale
        bgView.layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#C4C4C4", alpha: 0.1).cgColor
        bgView.layer.shadowOffset = CGSize(width: 0, height: -8)
        bgView.layer.shadowRadius = 9*widthScale
        bgView.layer.shadowOpacity = 1
        contentView.addSubview(bgView)
        
        tagImageView = UIImageView()
        bgView.addSubview(tagImageView)
        
        logoImageView = UIImageView()
        bgView.addSubview(logoImageView)
        
        labelBgImageView = UIImageView()
        bgView.addSubview(labelBgImageView)
        
        nameLabel = HWLabel.createBoldLabel(title: "小张做代理超牛", color: "#FFBC2E", font: 12*widthScale)
        nameLabel.textAlignment = .center
        labelBgImageView.addSubview(nameLabel)
        
        lowUserLabel = HWLabel.createLabel(title: "下级用户", color: "#888888", font: 12)
        bgView.addSubview(lowUserLabel)
        
        lowUserNumLabel = HWLabel.createBoldLabel(title: "1234", color: "#333333", font: 14*widthScale)
        bgView.addSubview(lowUserNumLabel)
    }
    
    private func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.left.right.top.bottom.equalToSuperview()
        }
        
        tagImageView.snp.makeConstraints { make in
            make.left.top.equalTo(10*widthScale)
            make.width.height.equalTo(18*widthScale)
        }
        
        logoImageView.snp.makeConstraints { make in
            make.left.equalTo(25*widthScale)
            make.top.equalTo(34*widthScale)
            make.width.equalTo(60*widthScale)
            make.height.equalTo(43*widthScale)
        }
        
        labelBgImageView.snp.makeConstraints { make in
            make.left.equalTo(3*widthScale)
            make.right.equalTo(-3*widthScale)
            make.height.equalTo(22*widthScale)
            make.top.equalTo(logoImageView.snp.bottom).offset(10*widthScale)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        lowUserLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(labelBgImageView.snp.bottom).offset(6*widthScale)
        }
        
        lowUserNumLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(lowUserLabel.snp.bottom).offset(5*widthScale)
        }
    }
}
